package org.xyl;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.xyl.McpServerApplication;
import org.xyl.service.McpService;
import static org.junit.jupiter.api.Assertions.*;

/**
 * MCP服务测试类
 */
@SpringBootTest(classes = McpServerApplication.class)
public class McpServiceTest {
    
    @Autowired
    private McpService mcpService;
    
    @BeforeEach
    void setUp() {
        assertNotNull(mcpService, "McpService应该被成功注入");
    }
    
    @Test
    public void testSearchKnowledgeBase() {
        var results = mcpService.searchKnowledgeBase("ESL-202 心跳间隔", "手册", 5);
        assertNotNull(results);
        assertFalse(results.isEmpty());
        System.out.println("知识库搜索测试通过，返回结果数: " + results.size());
    }
    
    @Test
    public void testGetDeviceStatus() {
        var status = mcpService.getDeviceStatus("A123");
        assertNotNull(status);
        assertEquals("A123", status.getDeviceId());
        System.out.println("获取设备状态测试通过，设备ID: " + status.getDeviceId());
    }
    
    @Test
    public void testAnalyzeDeviceLogs() {
        var result = mcpService.analyzeDeviceLogs("A123", "24h");
        assertNotNull(result);
        assertNotNull(result.getSummary());
        System.out.println("分析设备日志测试通过，摘要: " + result.getSummary());
    }
    
    @Test
    public void testCreateSupportTicket() {
        var ticket = mcpService.createSupportTicket(
            "上海超市", 
            "A123", 
            "设备刷新慢", 
            "高"
        );
        assertNotNull(ticket);
        assertNotNull(ticket.getTicketId());
        System.out.println("创建支持工单测试通过，工单ID: " + ticket.getTicketId());
    }
}
